import type { Router } from 'vue-router'

import AppProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { showProgressBar } from '/@lib/config';

export function setupProgressGuard(router: Router) {
  AppProgress.configure({
    easing: 'ease',
    speed: 500,
    trickleSpeed: 200,
    showSpinner: true
  });

  router.beforeEach(() => {
    if (showProgressBar) AppProgress.start();
    // next()
  });
  router.afterEach(() => {
    if (AppProgress.status) AppProgress.done();
  });

  router.onError((error) => {
    if (AppProgress.status) AppProgress.done();
    console.warn('路由错误:', error.message);
  });
}
